import type { WmsStock } from "@/pages/wms/stock/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //产品物料ID
  materialId?: number;
  //入库批次号
  batchCode?: string;
  //仓库ID
  warehouseId?: number;
  //库区ID
  locationId?: number;
  //库位ID
  areaId?: number;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: WmsStock[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/wms/stock/pageList",
    data
});
const getInfo = (id: React.Key): Promise<WmsStock> =>
  apiClient.get({
    url: `/wms/stock/${id}`
});

const add = (data: WmsStock): Promise<WmsStock> =>
  apiClient.post({
    url: "/wms/stock",
    data
});

const update = (data: WmsStock): Promise<WmsStock> =>
  apiClient.put({
    url: "/wms/stock",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/wms/stock",
    params: {
    ids: ids.join(",")
  }
});

const recordPageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/wms/stock/record/pageList",
    data
});

export const wmsStockService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  recordPageList
};

export default wmsStockService;